<template>
    <div class="pie">
        <div :id="'myChart' + cageId" :style="styles"></div>
    </div>
</template>

<script>
import echarts from 'echarts';
export default {
  data () {
    return {
      // xData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      // paramsData: [820, 932, 901, 934, 1290, 1330, 1320],
      // title: '折线图',
      cageId: parseInt(Math.random() * 100000)
    };
  },
  watch: {
    paramsData () {
      this.drawLine();
    }
  },
  mounted () {
    if (this.paramsData) {
      this.drawLine();
    }
  },
  props: {
    // 样式
    styles: Object,
    // 参数数据
    paramsData: Array,
    // 提示数据
    xData: Array,
    // 标题
    title: String
  },
  methods: {
    drawLine () {
      let that = this;
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('myChart' + that.cageId));
      // 绘制图表
      myChart.setOption({
        title: {
          text: that.title
        },
        tooltip: {
          trigger: 'none',
          axisPointer: {
            type: 'cross'
          }
        },
        grid: {
          top: 70,
          bottom: 50
        },
        xAxis: {
          type: 'category',
          data: that.xData
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: that.paramsData,
          type: 'line',
          smooth: true
        }]
      });
    }
  }
};
</script>

<style lang="stylus" scoped>

</style>
